package exam;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class baidu {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        Integer[] nums = new Integer[n];
        int res=0;
        for(int i=0;i<n;i++){
            nums[i] =in.nextInt();
        }
        Arrays.sort(nums, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                String s1 = String.valueOf(o1);
                String s2 = String.valueOf(o2);
                return -(s1+s2).compareTo(s2+s1);
            }
        });
        System.out.println(res);

    }
}
